package GDoc::Job::Fetch::US::Exec::Ag::NASS::Cattle;

use Moose;

use File::Temp;


extends 'GDoc::Job::Fetch::US::Exec::Ag::NASS';

my @MONTHS = qw{January February March April May June July August September October November December};

sub setup { 
    my $self = shift;
    $self->_baseurl( 'http://usda.mannlib.cornell.edu/MannUsda/viewDocumentInfo.do?documentID=1017' );
}


sub _fetch_pdf { 
    my $self = shift;
    my %data = %{ $self->data };

    my $ident = sprintf( 'NASS-CATL-%04d-%02d', $data{year}, $data{month} );
    my $filename = $ident . '.pdf';
    my $key = 'us/exec/ag/nass/' . $filename;

    $self->logger->info( "Storing $data{link} --> $key" );

    my $mech = $self->_mech;
    my $tmpf = File::Temp->new;
    $mech->get( $data{link}, ':content_file' => $tmpf->filename );

    my $mname = $MONTHS[ $data{month} - 1 ];
    $self->store_pdf( key      => $key,
                      datafile => $tmpf,
                      filename => $filename,
                      meta     => { description   => "Cattle Report, $mname, $data{year}",
                                    identifier    => $ident,
                                  }
                    );

}


1;
